package com.fatdetection.demo.controller;

import com.fatdetection.demo.annotation.AuthAdmin;
import com.fatdetection.demo.annotation.AuthOperator;
import com.fatdetection.demo.bean.School;
import com.fatdetection.demo.service.SchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/school")
@AuthAdmin
@AuthOperator
public class SchoolController {

    @Autowired
    SchoolService schoolService;

    @GetMapping("/add")
    public Boolean insertSchool(School school){
        School school1 = new School();
        school1.setProvince("北京市");
        school1.setSchoolName("北京大学");
        return schoolService.insertSchool(school1);
    }

    @GetMapping("/del/{schoolName}")
    public Boolean delSchool(@PathVariable("schoolName") String name){
        return schoolService.delSchool(name);
    }

    @GetMapping("/findAll")
    public List<School> getAllSchool(){
        return schoolService.findAllSchool();
    }

    @GetMapping("/findSchoolByName/{schoolName}")
    public School getSchoolByName(@PathVariable("schoolName") String name){
        return schoolService.findSchoolByName(name);
    }

    @GetMapping("/findByProvince/{province}")
    public List<School> getByProvince(@PathVariable("province")String province){
        return schoolService.findSchoolByProvince(province);
    }
}
